home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Snippets / Toolbox / FindSysFolder / FindSysFolder
Encoding:
Text File  |  1992-07-15  |  1.5 KB  |  45 lines  |  [TEXT/MACA]

  1. Here's a snippet.  It returns the vRefNum and DirID of the System Folder.  It does it the right way under both 6.0 and 7.0.
  2.   ---------------
  3.   
  4.   #define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))
  5.   
  6.   /* FindSysFolder returns the (real) vRefNum, and the DirID of the current
  7.      system folder.  It uses the Folder Manager if present, otherwise it falls
  8.      back to SysEnvirons.  It returns zero on success, otherwise a standard
  9.      system error. */
  10.   
  11.   OSErr    FindSysFolder(short *foundVRefNum, long *foundDirID)
  12.   {
  13.       long            gesResponse;
  14.       SysEnvRec        envRec;
  15.       WDPBRec            myWDPB;
  16.       unsigned char    volName[34];
  17.       OSErr            err;
  18.       
  19.       
  20.       *foundVRefNum = 0;
  21.       *foundDirID = 0;
  22.       if (!Gestalt (gestaltFindFolderAttr, &gesResponse) &&
  23.           BTstQ (gesResponse, gestaltFindFolderPresent)) {    /* Does Folder Manager
  24.   exist? */
  25.               err = FindFolder (kOnSystemDisk, kSystemFolderType, kDontCreateFolder, 
  26.                   foundVRefNum, foundDirID);
  27.       } else {
  28.           /* Gestalt can't give us the answer, so we resort to SysEnvirons */
  29.           if (!(err = SysEnvirons (curSysEnvVers, &envRec))) {
  30.               myWDPB.ioVRefNum = envRec.sysVRefNum;
  31.               volName[0] = '\000';                    /* Zero volume name */
  32.               myWDPB.ioNamePtr = volName;
  33.               myWDPB.ioWDIndex = 0;
  34.               myWDPB.ioWDProcID = 0;
  35.               if (!(err = PBGetWDInfo (&myWDPB, 0))) {
  36.                   *foundVRefNum = myWDPB.ioWDVRefNum;
  37.                   *foundDirID = myWDPB.ioWDDirID;
  38.               }
  39.           }
  40.       }
  41.       return (err);
  42.   }
  43. ======================================================================
  44.  
  45.